package cn.iocoder.yudao.module.dt.service.activityadmin;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.dt.controller.admin.activityadmin.vo.*;
import cn.iocoder.yudao.module.dt.dal.dataobject.activityadmin.ActivityAdminDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.dt.convert.activityadmin.ActivityAdminConvert;
import cn.iocoder.yudao.module.dt.dal.mysql.activityadmin.ActivityAdminMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.dt.enums.ErrorCodeConstants.*;

/**
 * 活动管理员表，用作核销等权限 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ActivityAdminServiceImpl implements ActivityAdminService {

    @Resource
    private ActivityAdminMapper activityAdminMapper;

    @Override
    public Integer createActivityAdmin(ActivityAdminCreateReqVO createReqVO) {
        // 插入
        ActivityAdminDO activityAdmin = ActivityAdminConvert.INSTANCE.convert(createReqVO);
        activityAdminMapper.insert(activityAdmin);
        // 返回
        return activityAdmin.getId();
    }

    @Override
    public void updateActivityAdmin(ActivityAdminUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateActivityAdminExists(updateReqVO.getId());
        // 更新
        ActivityAdminDO updateObj = ActivityAdminConvert.INSTANCE.convert(updateReqVO);
        activityAdminMapper.updateById(updateObj);
    }

    @Override
    public void deleteActivityAdmin(Integer id) {
        // 校验存在
        this.validateActivityAdminExists(id);
        // 删除
        activityAdminMapper.deleteById(id);
    }

    private void validateActivityAdminExists(Integer id) {
        if (activityAdminMapper.selectById(id) == null) {
            throw exception(ACTIVITY_ADMIN_NOT_EXISTS);
        }
    }

    @Override
    public ActivityAdminDO getActivityAdmin(Integer id) {
        return activityAdminMapper.selectById(id);
    }

    @Override
    public List<ActivityAdminDO> getActivityAdminList(Collection<Integer> ids) {
        return activityAdminMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<ActivityAdminDO> getActivityAdminPage(ActivityAdminPageReqVO pageReqVO) {
        return activityAdminMapper.selectPage(pageReqVO);
    }

    @Override
    public List<ActivityAdminDO> getActivityAdminList(ActivityAdminExportReqVO exportReqVO) {
        return activityAdminMapper.selectList(exportReqVO);
    }

}
